package com.ylfstu.threaduse;

public class Thread02 {
    public static void main(String[] args) {
//        Dog dog = new Dog();
//        //底层使用了设计模式[代理模式]
//        Thread thread = new Thread(dog);
//        thread.run();

        Tiger tiger = new Tiger();
        ThreadProxy threadProxy = new ThreadProxy(tiger);
        threadProxy.start();
    }
}
class Animals{

}
class Tiger extends Animals implements Runnable{

    @Override
    public void run() {
        System.out.println("老虎嗷嗷叫...");
    }
}

//模拟了一个极简的Thread
class ThreadProxy implements Runnable{

    private Runnable target = null;//属性，类型是Runnable
    @Override
    public void run() {
        if (target != null) {
            target.run();//动态绑定 (运行类型tiger)
        }
    }
    public ThreadProxy(Runnable target) {
        this.target = target;
    }
    public void start() {
        start0();//这个方法实现多线程
    }
    public void start0() {

    }

}

class Dog implements Runnable{
    int count = 0;
    @Override
    public void run() {
        while (true) {
            System.out.println("小狗旺旺叫..." + (++count) + Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (count == 8)
                break;
        }
    }
}